/*******************************************************************************
 * Copyright 2016 stfalcon.com
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.libcommon.timefromatter

import java.util.Date
import java.util.Locale

/**
 * Interface used to format dates before they were displayed (e.g. dialogs time, messages date
 * headers etc.).
 */
interface DateFormatter {

    /**
     * Formats an string representation of the date object.
     *
     * @param date The date that should be formatted.
     * @return Formatted text.
     */
    fun format(date: Date): String

    /**
     * 数字2位数对齐
     * @param value
     */
    fun format2d(value: Int): String {
        return format(value, 2)
    }

    /**
     * 数字对齐位数
     * @param value
     * @param digital
     */
    fun format(value: Int, digital: Int): String {
        return String.format(Locale.ENGLISH, "%0${digital}d", value)
    }
}
